var app = getApp();
Page({
    data:{
        curPage : "/zofui_sales/kill/index",
        page : {
            isend : false,
            doing : false,
            doo : 'kill',
            pdata : {
                op : 'list',
                page : 1,
                id : -1,
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
		
		var zfid = options.zfid ? options.zfid : '';
		var shopid = options.shopid ? options.shopid : '';
        
        self.setData({
            'page.pdata.status' : options.status ? options.status : 0,
            'page.pdata.shopid' : options.shopid ? options.shopid : 0,
            'page.pdata.zfid' : zfid,
        });

        app.com.getLocation(self,function(loc){
            self.setData({
                'page.pdata.lat' : loc.latitude,
                'page.pdata.lng' : loc.longitude,
            });
            app.com.auth(function(user){
                app.com.getPage(self,self.data.page,0,function(res){
                    var data = res.data.data;
                    self.setData({
                       datalist : data.list,
                       Pagetheme : res.data.data.params.style,
                       sharedata : res.data.data.sharedata,
                       killarr : res.data.data.killarr,
                    },function(){
                        self.setData({
                            inited : true,
                        });
                    });
                    
                    wx.setNavigationBarTitle({
                      title:  res.data.data.params.title ? res.data.data.params.title : '限时秒杀',
                    });

                },false,function(res){
                    app.com.alert(res.data.message);
                });
				app.com.setBar(app,self,shopid);
            });
        });
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : self.data.sharedata.img,
        }
    },
    onReachBottom : function(){
        var self = this;
        app.com.getPage(self,self.data.page,0,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    tabChange(e){
        var self = this;
        var id = e.currentTarget.dataset.id;
        var status = e.currentTarget.dataset.status;
        var start = e.currentTarget.dataset.start;

        if( self.data.ising || ( id == self.data.page.pdata.id ) ) return false;
        self.data.ising = true;

        self.setData({
            datalist : [],
            topstatus : status,
            'killarr.actid' : id,
            'page.pdata.id' : id,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0,
        });

        app.com.getPage(self,self.data.page,0,function(res){
            self.setData({
                datalist : res.data.data.list,
            });
            wx.pageScrollTo({
                scrollTop: 0
            });
        });
        self.data.ising = false;

        if( start > 0 ) {
            self.countTime(start);
        }

    },
    countTime(start){
        var self = this;
        clearInterval(self.data.timer);
        self.setData({
            start : start,
        });
        self.data.timer = setInterval(function(){
            var date = new Date();
            var time = date.getTime();
            
            var endTime = self.data.start + '000';
            var lag = (endTime*1 - time);
            if(lag > 0){
                var second = Math.floor(lag/1000%60);     
                var minite = Math.floor(lag/1000/60%60);
                var hour = Math.floor(lag/1000/60/60%24);
                var day = Math.floor(lag/1000/60/60/24);
            }else{
                var second = '0';
                var minite = '0';
                var hour = '0';
                var day = '0';
            }
            self.setData({
                ['downtime'] : {day:day,hour:hour,minite:minite,second:second}
            });
        },1000);
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    }
    

})